package artid.com.arttogo.network;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Service;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager.OnActivityResultListener;
import android.text.TextUtils;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;
import com.ta.utdid2.android.utils.StringUtils;
import com.umeng.socialize.bean.CustomPlatform;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.OnSnsPlatformClickListener;
import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener;
import com.umeng.socialize.controller.listener.SocializeListeners.UMShareBoardListener;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.utils.Log;
import com.umeng.socialize.utils.SocializeUtils;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.activity.ChatActivity;
import artid.com.arttogo.activity.LoginActivity;
import artid.com.arttogo.activity.ReportActivity;
import artid.com.arttogo.app.ArtToGoApp;
import artid.com.arttogo.bean.ArtFavorite;
import artid.com.arttogo.bean.EaseOffLineMessageBean;
import artid.com.arttogo.bean.OneStateIntParser;
import artid.com.arttogo.bean.UserItem;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.db.DataKeeper;
import artid.com.arttogo.utils.Constant;
import artid.com.arttogo.utils.MySharedPreferences;
import artid.com.arttogo.utils.ToastUtil;

import static android.R.attr.type;

public class AppUtil {
    public static boolean isTest = false;
    public static UMSocialService mController;
    private static UserItem user;

    public static String picWidthSmallUrl = "_" + "100" + "x10.png";
    public static String picWidthMidUrl = "_" + "100" + "x10.png";
    public static String hxTalkPwd = "yjbgp2016";
    public static String deviceWidth = "500";
    public static String picWidthUrl = "_" + "500" + "x10.png";
    public static String picBigWidthUrl = "_" + "800" + "x10.png";
    //	public static Boolean isCltDet = false;
    public static String TAG_NEWS = "news";
    public static String TAG_TALK = "talk";
    public static String TAG_COLLECT = "collect";
    public static String TAG_AUCTION = "auction";//拍卖行分享标识
    static String shareTag = "";

    public static void Intent(Context packageContext, Class<?> cls) {
        Intent intent = new Intent(packageContext, cls);
        packageContext.startActivity(intent);
    }

    public static void Intent(Context packageContext, Class<?> cls,
                              Bundle bundle) {
        Intent intent = new Intent(packageContext, cls);
        intent.putExtras(bundle);
        packageContext.startActivity(intent);
    }

    public static void setUser() {
        AppUtil.user = (UserItem) DataKeeper.readSerializable(
                ArtToGoApp.getContext(), UserItem.class);
        if (AppUtil.user == null) {
            AppUtil.user = new UserItem();
        }
    }

    public static boolean LoginVer(Context mContext) {
        System.out.println(getUser().toString());
        if (isNeedLogin()) {
            ActivityManager activityManager = (ActivityManager) mContext
                    .getSystemService(Context.ACTIVITY_SERVICE);
            String runningActivity = activityManager.getRunningTasks(1).get(0).topActivity
                    .getClassName();
            if (runningActivity.contains("LoginActivity")) {
                return false;
            }
            Intent mIntent = new Intent(mContext, LoginActivity.class);
            mContext.startActivity(mIntent);

        }
        return isNeedLogin();
    }

    public static UserItem getUser() {
        if (user == null) {
            setUser();
        }
        return user;
    }

    public static boolean isNeedLogin() {
        return !getUser().isLogin();
    }

    public static void Logout(Context context) {
        MySharedPreferences.getMySharedPreferences(context).setValue("umToken",
                "");
        getUser().setLogin(false);
        getUser().setToken("");
        DataKeeper.keepSerializable(context, getUser());
        setUser();

    }

    /******
     * 监听器 start
     *******/
    private static List<OnActivityResultListener> list;

    public static void addOnActivatyResultListener(OnActivityResultListener l) {
        if (null == list) {
            list = new ArrayList<OnActivityResultListener>();
        }
        if (l != null && !list.contains(l)) {
            list.add(l);
        }
    }

    public static void onActivityResult(int requestCode, int resultCode,
                                        Intent data) {
        if (list == null) {
            return;
        }
        for (OnActivityResultListener l : list) {
            l.onActivityResult(requestCode, resultCode, data);
        }
    }

    static int sharePicId = R.mipmap.icon05;
    static String uidTalk = "", headurl = "", aname;

    public static void shareWithTalk(final Context context, String title1,
                                     String shareContent, String imageUrl, final String target_url,
                                     String uid, String head, String aName) {
        shareTag = TAG_NEWS;
        uidTalk = uid;
        headurl = head;
        aname = aName;
        showShare(context, title1, shareContent, imageUrl, target_url);

    }

    /**
     * 艺术品详情分享
     *
     * @param context
     * @param title1
     * @param shareContent
     * @param imageUrl
     * @param target_url
     * @param uid
     * @param head
     * @param aName
     */
    static String id = "";
    /**
     * 是否已经收藏
     */
    public static Boolean isCollect = false;

    public static void shareClt(final Context context, String title1,
                                String shareContent, String imageUrl, final String target_url,
                                String cid, Boolean isclt) {
        shareTag = TAG_COLLECT;
        id = cid;
        isCollect = isclt;
        showShare(context, title1, shareContent, imageUrl, target_url);

    }

    //	public static Boolean isNews = false;

    /**
     * 资讯收藏
     * @param context 上下文
     * @param title1   标题
     * @param shareContent 分享内容
     * @param imageUrl 分享图片
     * @param target_url 分享链接
     * @param cid  举报/收藏ID
     * @param isclt 是否收藏
     */
    public static void shareNews(final Context context, String title1,
                                 String shareContent, String imageUrl, final String target_url,
                                 String cid, Boolean isclt) {
        shareTag = TAG_NEWS;
        id = cid;
        isCollect = isclt;
        showShare(context, title1, shareContent, imageUrl, target_url);

    }

    /**
     * 图录的分享
     */
    static String zxid = "";
//	public static Boolean isNews = false;

    public static void shareOR(final Context context, String title1,
                               String shareContent, String imageUrl, final String target_url) {
        showShare(context, title1, shareContent, imageUrl, target_url);

    }

    /**
     * 拍卖行的分享
     *
     * @param context 上下文
     * @param type 举报和收藏的标识(1,机构，2，拍卖会，3专场，4拍品,5评论)
     * @param title1    标题
     * @param shareContent    分享内容
     * @param imageUrl    分享图片
     * @param target_url    分享网址
     * @param cid        举报/收藏ID
     * @param isclt    是否收藏
     */
    public static String reportAndCollectionType;

    public static void shareAuction(final Context context, String type, String title1,
                                    String shareContent, String imageUrl, final String target_url,
                                    String cid, Boolean isclt) {
        id = cid;
        shareTag = TAG_AUCTION;
        isCollect = isclt;
        reportAndCollectionType = type;
        if(!StringUtils.isEmpty(AppUtil.getUser().getToken())){
            showShare(context, title1, shareContent, imageUrl+"_100x10.png", target_url);
        }else{
            AppUtil.Logout(context);
            AppUtil.LoginVer(context);
        }
    }


    public static void testChat(final Context context, String uid,
                                String headurl, String title, String imgurl) {
        if (AppUtil.LoginVer(context)) {
            return;
        }
        EMMessage message = EMMessage.createTxtSendMessage("#" + title + "#",
                uid);
        // A端头像
        message.setAttribute("A_head", headurl);
        // A端名字
        message.setAttribute("A_name", aname);
        // 作品名字
        message.setAttribute("artDescribe", title);
        // C端头像
        message.setAttribute("artistURL", AppUtil.getUser().getHeadurl());
        // C端名字
        message.setAttribute("fromName", AppUtil.getUser().getRealname());
        // C端Uid
        message.setAttribute("C_uid", AppUtil.getUser().getUid());
        // 作品地址
        message.setAttribute("artUrl", imgurl);
        // IOS标识图文混排
        message.setAttribute("msgtype", "msgtype");
        EaseOffLineMessageBean bean = new EaseOffLineMessageBean();
        bean.setA_head(headurl);
        bean.setA_name(uid);
        bean.setArtDescribe(title);
        bean.setArtistURL(AppUtil.getUser().getHeadurl());
        bean.setC_uid(AppUtil.getUser().getUid());
        bean.setFromName(AppUtil.getUser().getRealname());
        bean.setArtUrl(imgurl);
        String em_apns_ext = new Gson().toJson(bean);
        // 离线消息
        message.setAttribute("em_apns_ext", em_apns_ext);
        EMClient.getInstance().chatManager().sendMessage(message);
        Intent intent = new Intent(context, ChatActivity.class);
        Bundle bundle = new Bundle();
        bundle.putParcelable("message", message);
        intent.putExtras(bundle);
        ChatActivity.message = message;
        context.startActivity(intent);
    }

    /**
     * 环信第一次不聊天
     *
     * @param context
     * @param uid
     * @param headurl
     * @param title
     * @param imgurl
     */
    public static void chat(final Context context, String uid, String headurl,
                            String title, String imgurl) {
        if (AppUtil.LoginVer(context)) {
            return;
        }
        EMMessage message = EMMessage.createTxtSendMessage("#" + title + "#",
                uid);
        // A端头像
        message.setAttribute("A_head", headurl);
        // A端名字
        message.setAttribute("A_name", aname);
        // 作品名字
        message.setAttribute("artDescribe", title);
        // C端头像
        message.setAttribute("artistURL", AppUtil.getUser().getHeadurl());
        // C端名字
        message.setAttribute("fromName", AppUtil.getUser().getRealname());
        // C端Uid
        message.setAttribute("C_uid", AppUtil.getUser().getUid());
        // 作品地址
        message.setAttribute("artUrl", imgurl);
        // IOS标识图文混排
        message.setAttribute("msgtype", "msgtype");
        //是否发送消息
        message.setAttribute("isSendMessage",true);
        EaseOffLineMessageBean bean = new EaseOffLineMessageBean();
        bean.setA_head(headurl);
        bean.setA_name(uid);
        bean.setArtDescribe(title);
        bean.setArtistURL(AppUtil.getUser().getHeadurl());
        bean.setC_uid(AppUtil.getUser().getUid());
        bean.setFromName(AppUtil.getUser().getRealname());
        bean.setArtUrl(imgurl);
        String em_apns_ext = new Gson().toJson(bean);
        // 离线消息
        message.setAttribute("em_apns_ext", em_apns_ext);
        Intent intent = new Intent(context, ChatActivity.class);
        /*
        Bundle bundle = new Bundle();
        bundle.putParcelable("message", message);
        intent.putExtras(bundle);
        */
        ChatActivity.message = message;
        context.startActivity(intent);
    }

    /**
     * 进入环信聊天页面
     */
    public static void goChat(Context mContext, String Uid, String A_head,
                              String A_name) {
        if (AppUtil.LoginVer(mContext)) {
            return;
        }
        // 这里进入不聊天用null占位，不然会报错
        EMMessage mEMMessage = EMMessage.createTxtSendMessage("#" + "null"
                + "#", Uid);
        // A端头像
        mEMMessage.setAttribute("A_head", A_head);
        // A端名字
        mEMMessage.setAttribute("A_name", A_name);
        // 作品名字
        mEMMessage.setAttribute("artDescribe", "");
        // C端头像
        mEMMessage.setAttribute("artistURL", AppUtil.getUser().getHeadurl());
        // C端名字
        mEMMessage.setAttribute("fromName", AppUtil.getUser().getRealname());
        // C端Uid
        mEMMessage.setAttribute("C_uid", AppUtil.getUser().getUid());
        // 作品地址
        mEMMessage.setAttribute("artUrl", "");
        // IOS标识图文混排
        mEMMessage.setAttribute("msgtype", "msgtype");
        //是否发送消息
        mEMMessage.setAttribute("isSendMessage",false);
        EaseOffLineMessageBean bean = new EaseOffLineMessageBean();
        bean.setA_head(headurl);
        bean.setA_name(Uid);
        bean.setArtDescribe("");
        bean.setArtistURL(AppUtil.getUser().getHeadurl());
        bean.setC_uid(AppUtil.getUser().getUid());
        bean.setFromName(AppUtil.getUser().getRealname());
        bean.setArtUrl("");
        String em_apns_ext = new Gson().toJson(bean);
        // 离线消息
        mEMMessage.setAttribute("em_apns_ext", em_apns_ext);
        Intent intent = new Intent(mContext, ChatActivity.class);
        ChatActivity.message = mEMMessage;
        mContext.startActivity(intent);
    }

    // static Boolean isTalk = false;
    public static void showShare(final Context context, final String title1,
                                 String shareContent, final String imageUrl, final String target_url) {
        if (shareContent.length() > 20) {
            shareContent = shareContent.substring(0, 18) + "..";
        }
        Log.e("imageurl", imageUrl);
        Log.e("target_url", target_url);
        // ShareDialog dialog = new ShareDialog(this);
        // dialog.show();
        if (context == null) {
            return;
        }
        mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        SnsPostListener mSnsPostListener = new SnsPostListener() {

            @Override
            public void onStart() {
                // Toast.makeText(context,
                // "分享开始", Toast.LENGTH_SHORT)
                // .show();
            }

            @Override
            public void onComplete(SHARE_MEDIA platform, int stCode,
                                   SocializeEntity entity) {
                if (stCode == 200) {
                    // requestReduceMoney();

                } else {
                    // Toast.makeText(context, "分享失败",
                    // Toast.LENGTH_SHORT).show();
                }
            }
        };
        mController.registerListener(mSnsPostListener);
        // 设置分享内容
        mController.setShareContent(shareContent);
        mController.setShareMedia(new UMImage(context, imageUrl));
        mController.setShareImage((new UMImage(context, imageUrl)));
        // mController.setShareImage((new UMImage(context, sharePicId)));
        CustomPlatform customPlatform = null;
        if (shareTag.equals(TAG_TALK)) {
            customPlatform = new CustomPlatform("悄悄询价", "悄悄询价", R.drawable.qqxj);
            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context2, SocializeEntity entity,
                                    SnsPostListener listener) {
                    testChat(context, uidTalk, headurl, title1, imageUrl);
                }
            };

        } else if (shareTag.equals(TAG_AUCTION)) {
            //拍卖行分享
            if (isCollect) {
                customPlatform = new CustomPlatform("收藏", "收藏", R.drawable.ysp_btn_collection_sel);
            } else {
                customPlatform = new CustomPlatform("收藏", "收藏", R.drawable.ysp_btn_collection_nor);
            }
            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context2, SocializeEntity entity, SnsPostListener listener) {
                    auctionCollection(context2, id, reportAndCollectionType, isCollect);
                }
            };
            //添加收藏图标(因接口问题现在只支持拍品收藏)
            if("4".equals(reportAndCollectionType)) {
                mController.getConfig().addCustomPlatform(customPlatform);
            }
            customPlatform = new CustomPlatform("举报", "举报", R.drawable.ysp_btn_jubao_nor);
            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context2, SocializeEntity entity, SnsPostListener listener) {
                    //举报
                    Intent intent = new Intent(context, ReportActivity.class);
                    intent.putExtra("id", id);
                    intent.putExtra("type", "5");
                    intent.putExtra("intentType", -2);
                    context2.startActivity(intent);


                }
            };
            mController.getConfig().addCustomPlatform(customPlatform);
        }

        // 资讯的分享

        else if (shareTag.equals(TAG_NEWS)) {
            if (!TextUtils.isEmpty(AppUtil.getUser().getToken())) {
                customPlatform = new CustomPlatform("举报", "举报",
                        R.drawable.ysp_btn_jubao_nor);
                customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                    @SuppressLint("NewApi")
                    @Override
                    public void onClick(Context context2, SocializeEntity entity,
                                        SnsPostListener listener) {
                        report(context2, id, "2");
                    }
                };
                mController.getConfig().addCustomPlatform(customPlatform);
            }

        } else if (shareTag.equals(TAG_COLLECT)) {
            if (isCollect) {
                customPlatform = new CustomPlatform("收藏", "收藏",
                        R.drawable.ysp_btn_collection_sel);
            } else {
                customPlatform = new CustomPlatform("收藏", "收藏",
                        R.drawable.ysp_btn_collection_nor);
            }

            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context2, SocializeEntity entity,
                                    SnsPostListener listener) {

                    reqCollect(id, isCollect, context2);
                }
            };
            mController.getConfig().addCustomPlatform(customPlatform);

            customPlatform = new CustomPlatform("举报", "举报",
                    R.drawable.ysp_btn_jubao_nor);
            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context2, SocializeEntity entity,
                                    SnsPostListener listener) {
                    report(context2, id, "3");
                }
            };
            mController.getConfig().addCustomPlatform(customPlatform);
        }
        //其他分享
        else {
            customPlatform = new CustomPlatform("复制链接", "复制链接", R.drawable.copy);
            customPlatform.mClickListener = new OnSnsPlatformClickListener() {
                @SuppressLint("NewApi")
                @Override
                public void onClick(Context context, SocializeEntity entity,
                                    SnsPostListener listener) {
                    Toast.makeText(context, "复制链接成功", Toast.LENGTH_SHORT)
                            .show();
                    SocializeUtils.sendAnalytic(context,
                            "com.umeng.custopm.copy_link", "分享内容", null,
                            "copy_link");
                    ClipboardManager myClipboard;
                    myClipboard = (ClipboardManager) context
                            .getSystemService(Service.CLIPBOARD_SERVICE);
                    ClipData cd = ClipData.newPlainText("label", target_url);
                    myClipboard.setPrimaryClip(cd);
                }
            };
            mController.getConfig().addCustomPlatform(customPlatform);
        }
        mController.getConfig().removePlatform(SHARE_MEDIA.SINA);
        mController.getConfig().removePlatform(SHARE_MEDIA.TENCENT);
        // // QQ分享
        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler((Activity) context,
                Constant.TENCENT_APP_KEY, Constant.TENCENT_APP_SECRET);
        qqSsoHandler.addToSocialSDK();
        QQShareContent qqShareContent = new QQShareContent();
        qqShareContent.setTitle(title1);
        qqShareContent.setShareContent(shareContent);
        qqShareContent.setShareImage(new UMImage(context, imageUrl));
        qqShareContent.setTargetUrl(target_url);
        mController.setShareMedia(qqShareContent);
        // QQ空间分享
        QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(
                (Activity) context, Constant.QZONE_APP_ID,
                Constant.QZONE_APP_KEY);
        qZoneSsoHandler.addToSocialSDK();
        QZoneShareContent qZoneShareContent = new QZoneShareContent();
        qZoneShareContent.setTitle(title1);
        qZoneShareContent.setShareContent(shareContent);
        qZoneShareContent.setShareImage(new UMImage(context, imageUrl));
        qZoneShareContent.setTargetUrl(target_url);
        mController.setShareMedia(qZoneShareContent);

        // 添加微信平台
        UMWXHandler wxHandler = new UMWXHandler(context, Constant.WX_APP_ID,
                Constant.WX_APP_KEY);
        wxHandler.addToSocialSDK();

        UMWXHandler wxCircleHandler = new UMWXHandler(context,
                Constant.WX_APP_ID, Constant.WX_APP_KEY);
        wxCircleHandler.setToCircle(true);
        wxCircleHandler.addToSocialSDK();

        WeiXinShareContent weixinContent = new WeiXinShareContent();
        weixinContent.setShareContent(shareContent);
        weixinContent.setTitle(title1);
        weixinContent.setTargetUrl(target_url);
        weixinContent.setShareMedia(new UMImage(context, imageUrl));
        mController.setShareMedia(weixinContent);

        // 设置朋友圈分享的内容
        CircleShareContent circleMedia = new CircleShareContent();
        circleMedia.setShareContent(shareContent);
        circleMedia.setTitle(title1 + "--" + shareContent);
        circleMedia.setTargetUrl(target_url);
        circleMedia.setShareImage(new UMImage(context, imageUrl));
        mController.setShareMedia(circleMedia);
        mController.getConfig().closeToast();

        mController.setShareBoardListener(new UMShareBoardListener() {

            @Override
            public void onShow() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onDismiss() {
                // TODO Auto-generated method stub
                // Log.e("!!!class",context.getClass().toString());

            }
        });

        mController.openShare((Activity) context, mSnsPostListener);

    }

    static void report(Context mContext, String id, String type) {
        Intent intent = new Intent(mContext, ReportActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("type", type);
        mContext.startActivity(intent);
    }

    static void reqCollect(final String id, final Boolean setCollect,
                           final Context mContext) {
        String state = "";
        if (setCollect) {
            state = "2";
        } else {
            state = "1";
        }
        String url = Cache.artFavorite;

        VolleyBasic.getInstance((Activity) mContext).post(
                url,
                VolleyMap.getInstance().artFavorite(
                        AppUtil.getUser().getToken(), id, state),
                ArtFavorite.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        if (vd.getCode() == -99) {
                            AppUtil.Logout((Activity) mContext);
                            AppUtil.LoginVer((Activity) mContext);
                            return;
                        }
                        if (setCollect) {
                            isCollect = false;
                        } else {
                            isCollect = true;
                        }

                        // if (itemArtistFollow.getState().equals("1")) {
                        // if (setCollect) {
                        // imgColl.setVisibility(View.VISIBLE);
                        // imgUncoll.setVisibility(View.GONE);
                        // try {
                        // int num = Integer.valueOf(strnum);
                        // num++;
                        // textsc.setText("收藏  ("
                        // + String.valueOf(num) + ")");
                        // } catch (Exception e) {
                        // // TODO: handle exception
                        // }
                        // } else {
                        // imgColl.setVisibility(View.GONE);
                        // imgUncoll.setVisibility(View.VISIBLE);
                        // try {
                        // int num = Integer.valueOf(strnum);
                        // num--;
                        // textsc.setText("收藏  ("
                        // + String.valueOf(num) + ")");
                        // } catch (Exception e) {
                        // // TODO: handle exception
                        // }
                        // }
                        // }

                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub

                    }
                });
    }

    /**
     * 资讯收藏
     * 收藏ID	contentid
     * 收藏状态	type	1：设置 2：取消
     */
    public static void InformationCollection(final Context mContext, final String id,final Boolean setCollect) {
        String state = "";
        if (setCollect) {
            state = "2";
        } else {
            state = "1";
        }

        VolleyBasic.getInstance((Activity) mContext).post(Cache.documentCollection,
                VolleyMap.getInstance().documentCollection(id, state),
                OneStateIntParser.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        OneStateIntParser mBean = (OneStateIntParser) vd.getData();
                        if (mBean.getState() == 1) {
                            if (setCollect) {
                                isCollect = false;
                            } else {
                                isCollect = true;
                            }
                            //发送资讯详情收藏状态
                            Intent intent0 = new Intent("com.ArtNewsDetailActivity.receiver");
                            intent0.putExtra("Collect", true);
                            intent0.putExtra("isCollect", isCollect);
                            mContext.sendBroadcast(intent0);
                            ToastUtil.toast(mContext, "操作成功");

                        } else {
                            ToastUtil.toast(mContext, "操作失败");
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub
                    }
                });
    }

    /**
     * 拍卖行收藏
     * 收藏ID	contentid
     * 收藏类型	inform_type	1,机构，2，拍卖会，3专场，4拍品
     * 收藏状态	setCollect	1：设置点赞   2：取消点赞
     */
    public static void auctionCollection(final Context mContext, final String id, final String inform_type, final Boolean setCollect) {
        String state = "";
        if (setCollect) {
            state = "2";
        } else {
            state = "1";
        }

        VolleyBasic.getInstance((Activity) mContext).post(Cache.addCollection,
                VolleyMap.getInstance().addCollection(id, inform_type, state),
                OneStateIntParser.class, new VolleyCallback() {

                    @Override
                    public void onSuccess(VolleyData vd) {
                        // TODO Auto-generated method stub
                        OneStateIntParser mBean = (OneStateIntParser) vd.getData();
                        if (mBean.getState() == 1) {
                            if (setCollect) {
                                isCollect = false;
                            } else {
                                isCollect = true;
                            }
                            //发送拍品详情收藏状态
                            Intent intent0 = new Intent("com.LotDetailFragment.receiver");
                            intent0.putExtra("Collect", true);
                            intent0.putExtra("isCollect", isCollect);
                            mContext.sendBroadcast(intent0);
                            //发送拍卖会详情收藏状态
                            Intent intent2 = new Intent("com.AuctionInfo_Activity.receiver");
                            intent2.putExtra("Collect", true);
                            intent2.putExtra("isCollect", isCollect);
                            mContext.sendBroadcast(intent2);
                            //发送拍卖行-专场详情收藏状态
                            Intent intent3 = new Intent("com.AuctionSpecialInfo_Activity.receiver");
                            intent3.putExtra("Collect", true);
                            intent3.putExtra("isCollect", isCollect);
                            mContext.sendBroadcast(intent3);
                            ToastUtil.toast(mContext, "操作成功");

                        } else {
                            ToastUtil.toast(mContext, "操作失败");
                        }
                    }

                    @Override
                    public void onError(VolleyError volleyError) {
                        // TODO Auto-generated method stub
                    }
                });
    }
}
